home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / Boxes / Message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-05  |  1.8 KB  |  87 lines  |  [TEXT/KAHL]

  1. /*
  2.     Display a message in a generic alert.
  3.     Comes up positioned by upper left of front window, which
  4.     presumably should be the window in which occurred the event to which the
  5.     alert applies.
  6.  
  7.     SetMessageAlertNum () should be called early to set the alert resource number.
  8. */
  9.  
  10. # include    "TransSkel.h"
  11.  
  12. # include    "Boxes.h"
  13.  
  14.  
  15. short    alrtNum = 0;
  16.  
  17.  
  18.  
  19. /* Public routine prototypes - copy into project main header file */
  20.  
  21. void    SetMessageAlertNum (short alrtNum);
  22. void    Message1 (StringPtr s1);
  23. void    Message2 (StringPtr s1, StringPtr s2);
  24. void    Message3 (StringPtr s1, StringPtr s2, StringPtr s3);
  25. void    Message4 (StringPtr s1, StringPtr s2, StringPtr s3, StringPtr s4);
  26.  
  27.  
  28. void SetMessageAlertNum (short n)
  29. {
  30.     alrtNum = n;
  31. }
  32.  
  33.  
  34. void Message4 (StringPtr s1, StringPtr s2, StringPtr s3, StringPtr s4)
  35. {
  36. AlertTHndl    h;
  37. Rect        r;
  38. WindowPtr    w = FrontWindow ();
  39. Point        pt;
  40.  
  41.     h = (AlertTHndl) GetResource ('ALRT', alrtNum);
  42.     if (h != nil)
  43.     {
  44.         if (w != nil)
  45.         {
  46.             pt.h = w->portRect.left;
  47.             pt.v = w->portRect.top;
  48.             LocalToGlobal (&pt);
  49.         }
  50.         else
  51.             SetPt (&pt, 40, 50);
  52.         HNoPurge ((Handle) h);
  53.         LoadResource ((Handle) h);
  54.         HLock ((Handle) h);
  55.         r = (**h).boundsRect;
  56.         OffsetRect (&r, -r.left, -r.top);        /* to (0, 0) */
  57.         OffsetRect (&r, pt.h + 10, pt.v + 10);    /* to upper left of front window */
  58.         (**h).boundsRect = r;
  59.         HUnlock ((Handle) h);
  60.     }
  61.     SetCursor (&arrow);
  62.     ParamText (s1, s2, s3, s4);
  63.     (void) Alert (alrtNum, SkelDlogFilter (nil, true));
  64.     SkelRmveDlogFilter ();
  65.     if (h != nil)
  66.         ReleaseResource ((Handle) h);
  67.     SkelDoUpdates ();
  68. }
  69.  
  70.  
  71. void Message1 (StringPtr s1)
  72. {
  73.     Message4 (s1, (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  74. }
  75.  
  76.  
  77. void Message2 (StringPtr s1, StringPtr s2)
  78. {
  79.     Message4 (s1, s2, (StringPtr) "\p", (StringPtr) "\p");
  80. }
  81.  
  82.  
  83. void Message3 (StringPtr s1, StringPtr s2, StringPtr s3)
  84. {
  85.     Message4 (s1, s2, s3, (StringPtr) "\p");
  86. }
  87.